package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}20:20
 */
public class LeetCode680 {
//    public boolean validPalindrome(String s) {
//        if (s.length() == 1 || s.length() == 0){
//            return true;
//        }
//        char[] c = s.toCharArray();
//        int left = 0;
//        int right = c.length - 1;
//        int count = 0;
//        while (left < right){
//            if (c[left] != c[right]) {
//                count++;
//                if (count == 1 && c.length == 3 || count > 1){
//                    return false;
//                }
//            }
//            left++;
//            right--;
//        }
//        return true;
//    }

    public boolean validPalindrome(String s){
        char[] c = s.toCharArray();
        int left = 0;
        int right = c.length - 1;
        return isPalindrome2(c,left,right,0);
    }

    private boolean isPalindrome(char[] chars,int i, int j){
        while ( i < j){
            if (chars[i] != chars[j]){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
    private boolean isPalindrome2(char[] chars,int i, int j, int count){
        if (count == 2){
            return false;
        }
        while ( i < j ){
            if (chars[i] != chars[j]){
                return isPalindrome2(chars,i + 1,j,count + 1) ||
                        isPalindrome2(chars,i,j - 1,count + 1);
            }
            i++;
            j--;
        }
        return true;
    }
    public static void main(String[] args) {
        String string = "eedede";
        System.out.println(new LeetCode680().isPalindrome2(string.toCharArray(),0,string.length() - 1,0));
    }
}
